package com.brayan.webapp.model.realestate;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

import com.brayan.webapp.model.general.geoinfo.GeoInfo;
import com.brayan.webapp.model.usermgmt.User;

/**
 * Entity implementation class for Entity: Reservation
 * 
 */
@Entity
public class Reservation implements Serializable {

	private static final long serialVersionUID = 1L;

	public Reservation() {
		super();
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@ManyToOne(fetch = FetchType.EAGER, optional=false, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH})
	@JoinColumn(name = "tenantId")
	private Tenant tenant;
	// References
	/** Set to eager, so that associated tuples are fetched, too. Set default 1 (Private) */
	@ManyToOne(fetch = FetchType.EAGER, optional=true, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH})
	@JoinColumn(name = "verifierId")
	private User verifier;
	
	@OneToOne(optional=true, cascade=CascadeType.ALL)	
	private GeoInfo geoInfo;

	@Enumerated(EnumType.STRING)
	private ReservationState reservationState = ReservationState.NEW;

	@Column
	private Date dateCreated;
	@Column
	private Date dateModified;


	@Column
	private Date startDate;

	@Column
	private Date endDate;
	
	@Column
	private Integer numberOfGuests;
	
	@JoinColumn
	@OneToOne(cascade=CascadeType.ALL)
	private Costs costs;

//	@Column
//	private Double rentalFee;
//	@Column
//	private Double cleaningFee;
	@Column(length = 1024)
	private String initialReservationComment;

	@JoinColumn
	@OneToOne(targetEntity = GTC.class)
	private GTC gtc;

	/***** EVENT HOOKS *****/
	@PrePersist
	protected void onCreate() {
		dateCreated = new Date();
	}

	@PreUpdate
	protected void onUpdate() {
		dateModified = new Date();
	}

	public Tenant getTenant() {
		return tenant;
	}

	public void setTenant(Tenant tenant) {
		this.tenant = tenant;
	}

	public User getVerifier() {
		return verifier;
	}

	public void setVerifier(User verifier) {
		this.verifier = verifier;
	}

	public ReservationState getReservationState() {
		return reservationState;
	}

	public void setReservationState(ReservationState reservationState) {
		this.reservationState = reservationState;
	}
	
	public void setReservationState(String reservationState){
		this.reservationState = ReservationState.valueOf(reservationState);
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public Integer getNumberOfGuests() {
		return numberOfGuests;
	}

	public void setNumberOfGuests(Integer numberOfGuests) {
		this.numberOfGuests = numberOfGuests;
	}

//	public double getRentalFee() {
//		return rentalFee;
//	}
//
//	public void setRentalFee(double rentalFee) {
//		this.rentalFee = rentalFee;
//	}
//
//	public double getCleaningFee() {
//		return cleaningFee;
//	}
//
//	public void setCleaningFee(double cleaningFee) {
//		this.cleaningFee = cleaningFee;
//	}

	public Costs getCosts() {
		return costs;
	}

	public void setCosts(Costs costs) {
		this.costs = costs;
	}

	public GTC getGtc() {
		return gtc;
	}

	public void setGtc(GTC gtc) {
		this.gtc = gtc;
	}

	public String getInitialReservationComment() {
		return initialReservationComment;
	}

	public void setInitialReservationComment(String initialReservationComment) {
		this.initialReservationComment = initialReservationComment;
	}

	public GTC getGTC() {
		return this.gtc;
	}

	public void setGTC(GTC gtc) {
		this.gtc = gtc;
	}

	public GeoInfo getGeoInfo() {
		return geoInfo;
	}

	public void setGeoInfo(GeoInfo geoInfo) {
		this.geoInfo = geoInfo;
	}

	public Long getId() {
		return id;
	}

	public Date getDateCreated() {
		return dateCreated;
	}

	public Date getDateModified() {
		return dateModified;
	}

}
